package cn.doitedu.day07

import cn.doitedu.day01.utils.SparkUtil

/**
 * @Date 22.4.6
 * @Created by HANGGE
 * @Description
 */
object C02_自定义累加器测试 {
  def main(args: Array[String]): Unit = {
    val sc = SparkUtil.getSc
    val rdd = sc.makeRDD(List("just so so so  ma ma hu hu hu"))
    val rdd2 = rdd.flatMap(_.split("\\s+"))
    // 1 创建累加器
    val accumulator = new MyAccumulator
    // 2 注册
    sc.register(accumulator)
    rdd2.foreach(e=>{
      // 3 加数据
      accumulator.add(e)
    })
    // 4 获取结果
    val mp: collection.Map[String, Int] = accumulator.value
    mp.foreach(println)


  }

}
